package com.yanggu.scala.chapater12.tuple

//模式匹配-匹配元祖
object MatchTupleDemo01 {

  def main(args: Array[String]): Unit = {
    //匹配元祖的时候使用(x: Int, _)或者(x, 0, y)即可
    //如果要匹配对偶元祖(10, 30)
    for (pair <- Array((0, 1), (1, 0), (10, 30), (1, 1), (1, 0, 2))) {
      val result = pair match {
        case (0, _) => "0..."
        case (y: Int, 0) => y
        //case语句具有优先级, 匹配成功后就不会继续执行了, 因此(10, 30)要写在(x, y)之前
        case (10, 30) => "元祖是(10, 30)"
        case (x, y) => (y, x)
        case (x, y, z) => (z, y, x)
        case _ => println("未匹配到数据")
      }
      println(result)
    }
  }

}
